package vn.mobisoft.gachno;

import java.io.IOException;
import java.util.Vector;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements NetworkInterface{	
	private TextView textDay;
	private TextView textTotal;
	private AutoCompleteTextView edit_search;
	
	private ImageButton btn_search;
	private ImageButton btn_search_dialog;
	//private Button btn_getRecord;
	
	private static final int 	DIALOG_DOWNLOAD_PROGRESS = 0;
	private static final int 	DIALOG_GACHNO_DS = 1;
	private ProgressDialog 		mProgressDialog;		
	
	private ListView list;
	private Runnable loadData;
	private View footerView;
	
	
	private MyCustomAdapter mAdapter;
	private MyCustomAdapter_ds mAdapter_ds;
	private int[] listcheck;
	private int gachno_loi;
	private int gachno_thanhcong;
	private int gachno_total;
	private Dialog dialog_gachno_ds;
	
	private Vector<ClientItem> mData = new Vector<ClientItem>();
	
	//private Network network = new Network();
	
	private int page		= 1;
	private int step		= 10;
	private int action 		= -1;
	private int totalRecord = -1;
	
	private Function function = new Function();
	
    private static final int MENU_GACH_DS 		= Menu.FIRST;    
    private static final int MENU_BAO_CAO 		= Menu.FIRST+1;    
    private static final int MENU_BC_THEO_DOT 	= Menu.FIRST+2; 
    private static final int MENU_SETTING 		= Menu.FIRST+42;
    
	private ArrayAdapter<String> adapter;
    
    private Convert convert = new Convert();
    private int selectedItem = -1;
    
    private String[] items;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //network.onConnectListener(this);
        //textCode = (TextView)findViewById(R.id.m_textView_code);
        textDay = (TextView)findViewById(R.id.m_textView_date);
        textTotal = (TextView)findViewById(R.id.m_textView_totalrecord);
        //editLog = (EditText)findViewById(R.id.m_editText_log_day);
        edit_search  = (AutoCompleteTextView)findViewById(R.id.m_autocomplete_edittext);
        
        btn_search = (ImageButton)findViewById(R.id.m_imageButton_search);
        
        btn_search.setOnClickListener(new View.OnClickListener() {			
			@Override
			public void onClick(View v) {
				String s = edit_search.getText().toString().trim();
				int pos = -1;
				for (int i=0; i<mData.size(); i++) {
					if (mData.elementAt(i).ten_khachhang.equals(s)) {
						pos = i;
						break;
					}
				}
				if (pos>=0) {
					selectedItem = pos;
					final CharSequence[] items = {	"Tên khách hàng: " + mData.elementAt(pos).ten_khachhang, 
													"Mã hóa đơn: " + mData.elementAt(pos).id_hoadon, 
													"Số đt: " + mData.elementAt(pos).so_dt,
													"Số nợ: " + toCurent(mData.elementAt(pos).tong_tien) +" vnđ"};
	
					AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
					builder.setTitle("Thông tin khách hàng");
					builder.setItems(items, null);
					
					builder.setPositiveButton("Thoát", new OnClickListener() {
						
						@Override
						public void onClick(DialogInterface dialog, int which) {
							
						}
					});
					
					builder.setNegativeButton ("Gạch nợ", new OnClickListener() {
						
						@Override
						public void onClick(DialogInterface dialog, int which) {
							onConnect(CONSTANT.ACTION_GACH_NO, mData.elementAt(selectedItem).id_hoadon, mData.elementAt(selectedItem).id_payment);
						}
					});
					
					AlertDialog alert = builder.create();
					alert.show();
				}
			}
		});
        
        btn_search_dialog = (ImageButton)findViewById(R.id.m_imageButton_searchform);
        btn_search_dialog.setOnClickListener(new View.OnClickListener() {			
			@Override
			public void onClick(View v) {
                //set up dialog
                final Dialog dialog = new Dialog(v.getContext());
                dialog.setContentView(R.layout.search);
                dialog.setTitle("Tìm kiếm khách hàng");
                dialog.setCancelable(true);
                //there are a lot of settings, for dialog, check them all out!
 
                //set up text
                final EditText text_hdid = (EditText) dialog.findViewById(R.id.s_editText_hd_id);
                final EditText text_dt = (EditText) dialog.findViewById(R.id.s_editText_sodt);
                //text.setText(R.string.lots_of_text);
 
                //set up image view
 
                //set up button
                Button button = (Button) dialog.findViewById(R.id.s_button_search);
                button.setOnClickListener(new View.OnClickListener() {
                @Override
                    public void onClick(View v) {
                		if (text_hdid.getText().toString().length()<=0 && text_dt.getText().toString().length()<=0) {
                			Toast.makeText(getApplicationContext(), "Cần nhập thông tin!", Toast.LENGTH_LONG).show();
                		}else {
                			onConnect(CONSTANT.ACTION_SEARCH_LIST, text_hdid.getText().toString(), text_dt.getText().toString());
                			dialog.dismiss();
                		}
                    }
                });
                //now that the dialog is set up, it's time to show it    
                dialog.show();
			}
        });
        
        //set gia tri
        //textCode.setText(getString(R.string.m_code)+((Global)getApplication()).getCode());
        textDay.setText(getString(R.string.m_date)+" "+Function.getDateMonthYear());
        //editLog.setEnabled(false);
        //editLog.setText(((Global)getApplication()).getLog());
        
/*        btn_getInfor.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				//Intent i = new Intent(getApplicationContext(), Setting.class);
				//startActivity(i);
				onConnect(CONSTANT.ACTION_GET_LIST_CLIENT);								
				
			}
		});
        
        btn_getRecord.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
			}
		});*/
        
        ((Global)getApplication()).updateMain(this);
        
        mAdapter = new MyCustomAdapter(this);  
        list = (ListView)findViewById(R.id.m_listView);
        list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
					long arg3) 
			{
				selectedItem = pos;
				final CharSequence[] items = {	"Tên khách hàng: " + mData.elementAt(pos).ten_khachhang, 
												"Mã hóa đơn: " + mData.elementAt(pos).id_hoadon, 
												"Số đt: " + mData.elementAt(pos).so_dt,
												"Số nợ: " + toCurent(mData.elementAt(pos).tong_tien) +" vnđ"};

				AlertDialog.Builder builder = new AlertDialog.Builder(arg1.getContext());
				builder.setTitle("Thông tin khách hàng");
				builder.setItems(items, null);
				
				builder.setPositiveButton("Thoát", new OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						
					}
				});
				
				builder.setNegativeButton ("Gạch nợ", new OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						onConnect(CONSTANT.ACTION_GACH_NO, mData.elementAt(selectedItem).id_hoadon, mData.elementAt(selectedItem).id_payment);
						dialog.dismiss();
					}
				});
				
				AlertDialog alert = builder.create();
				alert.show();
			}
		});        
        
        String value = "";//any text you are pre-filling in the edit_search
        //final edit_search et = new edit_search(this);
        //et.setText(value);
        final Drawable x = getResources().getDrawable(R.drawable.button_cancel);//your x image, this one from standard android images looks pretty good actually
        x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight());
        edit_search.setCompoundDrawables(null, null, value.equals("") ? null : x, null);
        edit_search.setOnTouchListener(new OnTouchListener() {
            
            public boolean onTouch(View v, MotionEvent event) {
                if (edit_search.getCompoundDrawables()[2] == null) {
                    return false;
                }
                if (event.getAction() != MotionEvent.ACTION_UP) {
                    return false;
                }
                if (event.getX() > edit_search.getWidth() - edit_search.getPaddingRight() - x.getIntrinsicWidth()) {
                    edit_search.setText("");
                    edit_search.setCompoundDrawables(null, null, null, null);
                }
                return false;
            }
        });
        
        edit_search.addTextChangedListener(new TextWatcher() {
            
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                edit_search.setCompoundDrawables(null, null, edit_search.getText().toString().equals("") ? null : x, null);
            }

            
            public void afterTextChanged(Editable arg0) {
            }

            
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
        });
        
        list.setAdapter(mAdapter);
		onConnect(CONSTANT.ACTION_GET_LIST_CLIENT);
    }
    
    /**
     * cap nhat text auto
     */
    private void updateAutoCompleteText() {
        // Get the string array        
    	String[] data = new String[mData.size()];
    	
    	for (int i=0; i< mData.size(); i++) {
    		data[i] = convert.UnicodeToKhongDau(mData.elementAt(i).ten_khachhang);
    	}    	
        // Create the adapter and set it to the AutoCompleteTextView 
        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, data);
        edit_search.setAdapter(adapter);
	}
    
    public void onConnect(int connectType, String... arg) {
    	action = connectType;
    	String link = "";
    	switch (connectType) {
    	
		case CONSTANT.ACTION_GET_LIST_CLIENT:
			link = String.format(CONSTANT.LINK_CLIENT_LIST, ((Global)getApplication()).getMid(), page+"", step+"");
			break;
		case CONSTANT.ACTION_TEST:
			link = String.format(CONSTANT.LINK_CLIENT_LIST, ((Global)getApplication()).getMid(), page+"", step+"");
			break;
		case CONSTANT.ACTION_GACH_NO:
			link = String.format(CONSTANT.LINK_GACHNO, ((Global)getApplication()).getCode(), arg[0], arg[1],  ((Global)getApplication()).getMid());
			break;	
		case CONSTANT.ACTION_SEARCH_LIST:
			link = String.format(CONSTANT.LINK_SEARCH_LIST, ((Global)getApplication()).getMid(), arg[0], arg[1]);
			break;	
		case CONSTANT.ACTION_GACH_NO_DS:
			int index = -1;
			for (int i=0; i<listcheck.length; i++) {
				if (listcheck[i]==2) {
					index = i;
					break;
				}
			}
			
			if (index>-1) {
				link = String.format(CONSTANT.LINK_GACHNO, ((Global)getApplication()).getCode(), mData.elementAt(index).id_hoadon, mData.elementAt(index).id_payment, ((Global)getApplication()).getMid());
				listcheck[index] = 1;
			}else {
				for (int i=0; i<listcheck.length; i++) {
					if (listcheck[i]==-1) {
						updateList(i);
						listcheck[i]=0;
					}
				}
				totalRecord -= gachno_total;
				textTotal.setText("Tổng: "+ totalRecord);
				dismissDialog(DIALOG_GACHNO_DS);
				dialog_gachno_ds.dismiss();
				Toast.makeText(getApplicationContext(), "Gạch danh sách thành công "+gachno_thanhcong+"/"+gachno_total, Toast.LENGTH_LONG).show();
				return;
			}
			
			break;	
		case CONSTANT.ACTION_DOT_GIAO:
			link = String.format(CONSTANT.LINK_DOT_GIAO, ((Global)getApplication()).getMid());
			break;
		default:
			break;
		} 
    	Network network = new Network();
    	network.onConnectListener(this);
    	network.execute(link);
    }
    
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		menu.add(0, MENU_GACH_DS	, 0,"Gạch danh sách").setIcon(android.R.drawable.ic_menu_delete);  	
		menu.add(0, MENU_BAO_CAO	, 0,"Báo cáo").setIcon(android.R.drawable.ic_menu_directions); 
		menu.add(0, MENU_BC_THEO_DOT, 0,"Báo cáo theo đợt").setIcon(android.R.drawable.ic_menu_report_image); 
		menu.add(0, MENU_SETTING	, 0,"Tùy chọn").setIcon(android.R.drawable.ic_menu_rotate); 
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// showMsg(item.getTitle().toString());
		switch (item.getItemId()) {
		case MENU_GACH_DS:
			listcheck = new int[mData.size()];
			// set up dialog
			dialog_gachno_ds = new Dialog(this);
			dialog_gachno_ds.setContentView(R.layout.list);
			dialog_gachno_ds.setTitle("Gạch nợ danh sách");
			dialog_gachno_ds.setCancelable(true);
			// there are a lot of settings, for dialog, check them all out!

			// set up text
			ListView list = (ListView) dialog_gachno_ds
					.findViewById(R.id.l_listView);
			mAdapter_ds = new MyCustomAdapter_ds(this);
			list.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1,
						int arg2, long arg3) {
					// TODO Auto-generated method stub

				}
			});
			list.setAdapter(mAdapter_ds);
			// set up button
			Button button_back = (Button) dialog_gachno_ds
					.findViewById(R.id.l_button_back);
			button_back.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					dialog_gachno_ds.dismiss();
				}
			});

			Button button_gachno_ds = (Button) dialog_gachno_ds
					.findViewById(R.id.l_button_gach_ds);
			button_gachno_ds.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					gachno_total = 0;
					for (int i = 0; i < listcheck.length; i++) {
						if (listcheck[i] == 2)
							gachno_total++;
					}
					gachno_loi = 0;
					gachno_thanhcong = 0;
					onConnect(CONSTANT.ACTION_GACH_NO_DS);
					// for (int i=0; i<listcheck.length; i++) {
					// System.out.println(listcheck[i]);
					// }
				}
			});
			// now that the dialog is set up, it's time to show it
			dialog_gachno_ds.show();
			break;
		case MENU_BAO_CAO:
			Intent intent = new Intent(this, Report.class);
			startActivity(intent);
			break;
		case MENU_BC_THEO_DOT:
			onConnect(CONSTANT.ACTION_DOT_GIAO);
			break;
		case MENU_SETTING:
			intent = new Intent(this, Setting.class);
			startActivity(intent);
			break;
		}
		return super.onOptionsItemSelected(item);
	}
	  
    public void updateLog() {
    	//editLog.setText(((Global)getApplication()).getLog());
    }
    
    private class MyCustomAdapter extends BaseAdapter {
        private LayoutInflater 		mInflater;
        private Context activity;
        
        public MyCustomAdapter(Context a) {
        	activity = a;
            mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }
        
        public int getCount() {
            return mData.size();
        }
 
        public ClientItem getItem(int position) {
            return mData.get(position);
        }
 
        public long getItemId(int position) {
            return position;
        }
 
		@Override
		public View getView(final int pos, View convertView, ViewGroup parent) {       	
    		convertView = mInflater.inflate(R.layout.report_item, null);  
    		
    		TextView name = (TextView)convertView.findViewById(R.id.ri_textView_name);
    		name.setText((pos+1)+": "+mData.elementAt(pos).ten_khachhang);
    		
    		TextView address = (TextView)convertView.findViewById(R.id.ri_textView_infor);
    		address.setText("ĐT: "+mData.elementAt(pos).so_dt);
    		
    		TextView money = (TextView)convertView.findViewById(R.id.ri_textView_money);
    		//int m= Integer.parseInt(mData.elementAt(pos).tong_tien);
    		//String s = String.format("%,d",m);
    		money.setText(toCurent(mData.elementAt(pos).tong_tien) +" vnđ");    		
            return convertView;
		}
    }
    
    private class MyCustomAdapter_ds extends BaseAdapter {
        private LayoutInflater 		mInflater;
        private Context activity;
        
        public MyCustomAdapter_ds(Context a) {
        	activity = a;
            mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }
        
        public int getCount() {
            return mData.size();
        }
 
        public ClientItem getItem(int position) {
            return mData.get(position);
        }
 
        public long getItemId(int position) {
            return position;
        }
 
		@Override
		public View getView(final int pos, View convertView, ViewGroup parent) {       	
    		convertView = mInflater.inflate(R.layout.gach_ds_item, null);  
    		
    		TextView name = (TextView)convertView.findViewById(R.id.gds_textView_name);
    		name.setText((pos+1)+": "+mData.elementAt(pos).ten_khachhang);
    		
    		TextView address = (TextView)convertView.findViewById(R.id.gds_textView_infor);
    		address.setText("ĐT: "+mData.elementAt(pos).so_dt);
    		
    		TextView money = (TextView)convertView.findViewById(R.id.gds_textView_money);
    		//int m= Integer.parseInt(mData.elementAt(pos).tong_tien);
    		//String s = String.format("%,d",m);
    		money.setText(toCurent(mData.elementAt(pos).tong_tien) +" vnđ");  
    		
    		
    		CheckBox check = (CheckBox)convertView.findViewById(R.id.gds_checkBox1);
    		check.setOnCheckedChangeListener(new OnCheckedChangeListener() {
				
				@Override
				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
					if (isChecked) listcheck[pos] = 2;
					else listcheck[pos] = 0;
				}
			});
    		
            return convertView;
		}
    }    
    
    public String toCurent(String s) {
		int m= Integer.parseInt(s);
		return String.format("%,d",m);
    }
    
	@Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
		case DIALOG_DOWNLOAD_PROGRESS:
			mProgressDialog = new ProgressDialog(this);
			mProgressDialog.setTitle("");
			mProgressDialog.setMessage("Xin chờ trong giây lát!");
			mProgressDialog.setCancelable(true);
			mProgressDialog.show();
			return mProgressDialog;
		case DIALOG_GACHNO_DS:
			mProgressDialog = new ProgressDialog(this);
			mProgressDialog.setTitle("");
			mProgressDialog.setMessage("Xin chờ trong giây lát!");
			mProgressDialog.setCancelable(true);
			mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
			mProgressDialog.show();
			return mProgressDialog;	
		default:
			return null;
		}
	}
		
	@Override
	public void startNetworkConnect() {
		if (action!=CONSTANT.ACTION_GACH_NO_DS) showDialog(DIALOG_DOWNLOAD_PROGRESS);
		else {
			showDialog(DIALOG_GACHNO_DS);
			mProgressDialog.setMax(gachno_total);
		}
	}

	@Override
	public void networkProgressUpdate(String... progress) {
		
	}

	@Override
	public void stopNetworkConnect(String result) {
		dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
		if (result==null) {
			return;
		}
			
		switch (action) {
		case CONSTANT.ACTION_GET_LIST_CLIENT:
			
			//cap nhat total record
			if (page==1) {
				String s[] = result.split("<br/>");
				if (s.length>1) {
					try {
						totalRecord = Integer.parseInt(s[0]);
					} catch (NumberFormatException e) {
						totalRecord = 0;
						e.printStackTrace();
					}
					textTotal.setText("Tổng: "+ totalRecord);
				} 
			}
				
			mData = function.parseClientList(result);
			updateAutoCompleteText();
			break;
		case CONSTANT.ACTION_TEST:
			System.out.println(result);
			break;
		case CONSTANT.ACTION_GACH_NO:
			if (result.equals("0")) {
				Toast.makeText(getApplicationContext(), "Gạch nợ lỗi!", Toast.LENGTH_LONG).show();
			}else if (result.equals("1")) {
				Toast.makeText(getApplicationContext(), "Gạch nợ thành công", Toast.LENGTH_LONG).show();
				updateList(selectedItem);
				onConnect(CONSTANT.ACTION_GET_LIST_CLIENT);
			}else {
				Toast.makeText(getApplicationContext(), "Gạch nợ lỗi!", Toast.LENGTH_LONG).show();
			}
			//System.out.println(result);
			break;
		case CONSTANT.ACTION_SEARCH_LIST:			
			//System.out.println(result);
			String[] arr = result.split(":");
			if (arr.length>=7) {
				final ClientItem ci = new ClientItem(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6]);
				
				final CharSequence[] items = {
						"Tên khách hàng: " + ci.ten_khachhang,
						"Mã hóa đơn: " + ci.id_hoadon,
						"Số đt: " + ci.so_dt,
						"Số nợ: " + toCurent(ci.tong_tien)
								+ " vnđ" };

				AlertDialog.Builder builder = new AlertDialog.Builder(
						this);
				builder.setTitle("Thông tin khách hàng");
				builder.setItems(items, null);

				builder.setPositiveButton("Thoát", new OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {

					}
				});

				builder.setNegativeButton("Gạch nợ", new OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						
						selectedItem = -1;
						for (int i=0; i<mData.size(); i++) {
							if (mData.elementAt(i).id_hoadon.equals(ci.id_hoadon)) {
								selectedItem = i;
								break;
							}
						}
						onConnect(CONSTANT.ACTION_GACH_NO,
								ci.id_hoadon,
								ci.id_payment);
						dialog.cancel();
						
					}
				});

				AlertDialog alert = builder.create();
				alert.show();
			}
			break;	
		case CONSTANT.ACTION_GACH_NO_DS:
			if (result.equals("0")) {
				gachno_loi++;
			}else if (result.equals("1")) {
				gachno_thanhcong ++;
			}else {

			}
			mProgressDialog.setProgress(gachno_loi+gachno_thanhcong);
			mProgressDialog.setTitle("Thành công: "+gachno_thanhcong);
			updateListGachnods();
			onConnect(CONSTANT.ACTION_GACH_NO_DS);
			//System.out.println(result);			
			break;	
		case CONSTANT.ACTION_DOT_GIAO:
			System.out.println(result);
			result = result.trim();
			result = result.replace("<br/>", "~");
			if (result.charAt(result.length()-1)=='~') 
				result = result.substring(0, result.length()-2);
			final String[] a = result.split("~");
			
			if (a.length>1) {
				AlertDialog.Builder builder = new AlertDialog.Builder(this);
				builder.setTitle("Pick a color");
				builder.setSingleChoiceItems(a, -1, new DialogInterface.OnClickListener() {
				    public void onClick(DialogInterface dialog, int item) {
				        //Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
				    	
				    	Intent intent = new Intent(getApplicationContext(), Report_dot.class);
				    	intent.putExtra("REPORT_INFOR", a[item]);
						startActivity(intent);
						dialog.dismiss();
				    }
				});
				AlertDialog alert = builder.create();
				alert.show();
			}
			break;
		default:
			break;
		}		
	}

	private void updateListGachnods() {
		for (int i=0; i<listcheck.length; i++) {
			if (listcheck[i]==1) {
				listcheck[i] = -1;				
			}
		}
		
	}

	private void updateList(int i) {
		if (i>0) {
			mData.removeElementAt(i);
			mAdapter.notifyDataSetChanged();
			totalRecord--;
			textTotal.setText("Tổng: "+ totalRecord);
		}else {
			
		}
	}

	@Override
	public void networkError(IOException e) {
		
	}	
}
